package mgslangpack;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class ViewBooking
{
    public ViewBooking() throws Exception
    {
        Button b1,b2,b3;
        final TextField tf1;
        final JFrame jf = new JFrame("Bookings");
        jf.setSize(750,750);
        jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        jf.setLayout(null);
        jf.setVisible(false);
        Container ctn=jf.getContentPane();
        ctn.setBackground(Color.LIGHT_GRAY);
        Font f1 = new Font("Times New roman",Font.BOLD,24);
        Font f2 = new Font("Times New roman",Font.BOLD,12);
        Label l1 = new Label("Booked Dates");
        l1.setBounds(150,10,250,40);
        l1.setFont(f1);
        jf.add(l1);
        Label l2=new Label("Enter Refference No. to see Clab member that made the booking:");
        l2.setBounds(10,600,380,40);
        l2.setFont(f2);
        jf.add(l2);
        final TextArea ta = new TextArea();
        ta.setBounds(100,50,540,500);
        ta.setEditable(false);
        ta.setBackground(Color.WHITE);
        jf.add(ta);
        
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        final Connection con = DriverManager.getConnection("jdbc:odbc:TheOZ_DB","","");
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM Bookings");
        while(rs.next())
        {
            String bd,ng,sid;
            bd=rs.getString(1);
            ng=rs.getString(2);
            sid=rs.getString(3);
            ta.append("\nBooked Date:\t\t"+bd+"\nNumber Of Guests:\t"+ng+"\nReffence:\t\t"+sid+"\n\n");
            ta.append(" ");
        }
        tf1 = new TextField();
        tf1.setBounds(400,600,200,25);
        jf.add(tf1);
        b1 = new Button("View");
        b1.setBounds(610,600,80,30);
        b1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e2)
                {
                try
                {
                    String idn,nm,sn,bk;
                    String iReff=tf1.getText();
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                    final Connection con = DriverManager.getConnection("jdbc:odbc:TheOZ_DB","","");
                    Statement st2 = con.createStatement();
                    ResultSet rs=st2.executeQuery("SELECT Member.MemID, Member.MemFirstName, Member.MemLastName, Bookings.BkReff FROM Services, Member,Bookings WHERE (Member.MemID=Services.MemID) and (Services.BkReff=Bookings.BkReff)");
                    while(rs.next())
                    {
                        idn = rs.getString(1);
                        nm = rs.getString(2);
                        sn = rs.getString(3);
                        bk = rs.getString(4);
                        if((bk.equals(iReff)))
                        {
                            JOptionPane.showMessageDialog(null,"\nID Number: \t"+idn+"\nName: \t\t"+nm+"\nSurname: \t"+sn+"\n\n","Staff Info.",
                                    +JOptionPane.INFORMATION_MESSAGE);
                            tf1.setText("");
                        }
                    }
                }
                catch(Exception e1){System.out.println("ERROR 1"+e1);}
            }
        }
        );        
        jf.add(b1);                    
        b2 = new Button("Back");
        b2.setBounds(150,650,80,30);
        b2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                try
                {
                    jf.hide();
                    new MenuStaff();
                }
                catch(Exception e1){}
            }
        }
        );
        jf.add(b2);
        b3=new Button("Quit");
        b3.setBounds(520,650,80,30);
        b3.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                try
                {
                    System.exit(0);
                }
                catch(Exception e1){}
            }
        }
        );
        jf.add(b3);
        jf.show();
    }

}
/******************************************************************************/